package BinaryTreePackage;

/**
 * @author Lzm
 * @version 1.0
 */
public class hasPathSum_ {


  public boolean backTracking(TreeNode root,int target){
    // 确定终止条件
    if (root.left == null && root.right == null && target == 0){
      return true;
    }
    if (root.left == null && root.right == null && target != 0){
      return false;
    }
    // 单层处理逻辑
    if (root.left != null){
      target += root.left.val;
      if (backTracking(root.left,target)) return true;
      target -= root.left.val;
    }
    if (root.right != null){
      target += root.right.val;
      if (backTracking(root.right,target)) return true;
      target -= root.right.val;
    }
    return false;
  }
}
